%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "y.tab.h"
char glid[30];

void puttable (char id[30], char tipod[20], char vof[10]);

int comLevel = 0;
%}
%s COM
%s DECL
%s IDEST
%option noyywrap


INT				[0-9]+
REAL				[0-9]+("."[0-9]+)
TRUE				"true"
FALSE				"false"
ENTER  				\n|\r|\r\n
SPACE				[\t ]
LITERAL				 \"[^\"\r\n]*\"
ID				[a-zA-Z][a-zA-Z0-9]*
COMMENTIN			\/\/[^\n]*
COMMENTML			\/\*[^{ENDCOM}]*\*\/
ENDCOM				\*\/

MIN				"<"
GRT				">"
MINE				"<="
GRTE				">="
EQ				"=="
ASSIGN				"="
NEG				"!="
PLUS				"+"
MINUS				"-"
BY				"*"
DIVIDE				"/"
OPEN_PAREN			"("
CLOSE_PAREN			")"
MOD				"%"

COMMA				","
COLON				":"
SEMICOLON			";"
DOT				"."
OPEN_BRACE			"{"
CLOSE_BRACE			"}"
OPEN_BRACKET			"["
CLOSE_BRACKET			"]"
ARROW				"->"


IF					"if"
ELSEIF				"elseif"
THEN				"then"
IFNEVER				"ifnever"
IFQUIT				"ifquit"
QUIT				"quit"
ELSE				"else"
LOOP				"loop"
WHILE				"while"
QUOTATION_MARK			"\""

FUNCTION			"function"
	
T_INT				"int"
T_REAL				"real"
T_STRING			"string"
T_BOOLEAN				"boolean"

AND				"and"
OR				"or"
NOT				"!"
ERROR				\"[^\"\n\r/<<EOF>>]*



%%




{REAL}				{yylval.cadena = strdup(yytext); return REAL;}
{INT}				{yylval.cadena = strdup(yytext); return INT;}
{TRUE}				{yylval.cadena = strdup(yytext); return TRUE;}
{FALSE}				{yylval.cadena = strdup(yytext); return FALSE;}
{ENTER}				;
{SPACE}				;

{COMMENTIN}			;
{COMMENTML}			;

{T_INT}				{yylval.cadena = strdup(yytext); return T_INT;}
{T_REAL}			{yylval.cadena = strdup(yytext); return T_REAL;}
{T_BOOLEAN}			{yylval.cadena = strdup(yytext); return T_BOOLEAN;}
{T_STRING}			{yylval.cadena = strdup(yytext); return T_STRING;}
{IF}				{yylval.cadena = strdup(yytext); return IF;}
{ELSEIF}			{yylval.cadena = strdup(yytext); return ELSEIF;}
{THEN}				{yylval.cadena = strdup(yytext); return THEN;}
{IFNEVER}			{yylval.cadena = strdup(yytext); return IFNEVER;}
{IFQUIT}			{yylval.cadena = strdup(yytext); return IFQUIT;}
{QUIT}				{yylval.cadena = strdup(yytext); return QUIT;}
{ELSE}				{yylval.cadena = strdup(yytext); return ELSE;}
{LOOP}				{yylval.cadena = strdup(yytext); return LOOP;}
{WHILE}				{yylval.cadena = strdup(yytext); return WHILE;}
{FUNCTION}			{yylval.cadena = strdup(yytext); return FUNCTION;}

{COMMA}				{yylval.cadena = strdup(yytext); return COMMA;}
{COLON}				{yylval.cadena = strdup(strdup(yytext)); return COLON; }
{SEMICOLON}			{yylval.cadena = strdup(strdup(yytext)); return SEMICOLON; }
{DOT}				{yylval.cadena = strdup(yytext); return DOT; }
{OPEN_BRACE}			{yylval.cadena = strdup(yytext); return OPEN_BRACE; }
{CLOSE_BRACE}			{yylval.cadena = strdup(yytext); return CLOSE_BRACE; }
{OPEN_BRACKET}			{yylval.cadena = strdup(yytext); return OPEN_BRACKET; }
{CLOSE_BRACKET}			{yylval.cadena = strdup(yytext); return CLOSE_BRACKET; }
{ARROW}				{yylval.cadena = strdup(yytext); return ARROW; }

{MIN}				{yylval.cadena = strdup(yytext); return MIN; }
{GRT}				{yylval.cadena = strdup(yytext); return GRT; }
{MINE}				{yylval.cadena = strdup(yytext); return MINE; }
{GRTE}				{yylval.cadena = strdup(yytext); return GRTE; }
{EQ}				{yylval.cadena = strdup(yytext); return EQ; }
{ASSIGN}			{yylval.cadena = strdup(yytext); return ASSIGN; }
{NEG}				{yylval.cadena = strdup(yytext); return NEG; }
{PLUS}				{yylval.cadena = strdup(yytext); return PLUS; }
{MINUS}				{yylval.cadena = strdup(yytext); return MINUS; }
{BY}				{yylval.cadena = strdup(yytext); return BY; }
{DIVIDE}			{yylval.cadena = strdup(yytext); return DIVIDE; }
{OPEN_PAREN}			{yylval.cadena = strdup(yytext); return OPEN_PAREN; }
{CLOSE_PAREN}			{yylval.cadena = strdup(yytext); return CLOSE_PAREN; }
{MOD}				{yylval.cadena = strdup(yytext); return MOD; }

{AND}				{yylval.cadena = strdup(yytext); return AND; }
{OR}				{yylval.cadena = strdup(yytext); return OR; }
{NOT}				{yylval.cadena = strdup(yytext); return NOT; }

{LITERAL}			{yylval.cadena = strdup(yytext); return LITERAL;}
{ID}				{yylval.cadena = strdup(yytext); return ID;}

[^" "]				{printf ("Lexical error\n");exit(1);}
{ERROR}				{printf ("Lexical error\n");exit(1);}

%%

void puttable (char id[30], char vof[10], char tipod[20])
{
	
	//fprintf (stdout, "%s\t%s\t%s\t\n", id, vof, tipod);
	return;
}
